/**
  * @description: 「主持风采/编辑资料/添加个人二维码」页面
  * @author: Ruan Jiazhen
  * @date: 2024-03-11 13:58:32
**/


Page({
  data: {
    qrCodeUrl: '',
    eventChannel: null,
  },
  onLoad(options) {
    this.setData({
      qrCodeUrl: options.qrCodeUrl,
    });
    this.data.eventChannel = this.getOpenerEventChannel();
  },
  deleteQrCode() {
    this.setData({
      qrCodeUrl: '',
    });
    this.data.eventChannel.emit('deleteQrCode');
  },
  async addQrCode() {
    const qrCodeUrl = await new Promise<string>((resolve) => {
      wx.chooseMedia({
        mediaType: ['image'],
        count: 1,
        success(res) {
          resolve(res.tempFiles[0].tempFilePath);
        },
      });
    });
    this.setData({
      qrCodeUrl,
    });
    this.data.eventChannel.emit('addQrCode', qrCodeUrl);
  },
});
